package com.study.zgw.nio;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

public class HelloTwo {
    public static void main(String[] args) throws IOException {
        String source = "D:\\桌面文件\\123\\logo";
        String sc = "D:\\桌面文件\\123\\xplogo";
//        String target = "D:\\其他-back";
        //4
        Files.walk(Paths.get(sc)).forEach(path -> {
//            String targetName = path.toString().replace(source, target);
            try {
                //判断是目录 则创建目录
                if (Files.isDirectory(path)) {
//                    System.out.println("=====>目录名称："+path.toString());
//                    Files.createDirectory(Paths.get(targetName));
                } else if (Files.isRegularFile(path)) {
//                    System.out.println("=====>文件路径及名称："+path.toString());
                    System.out.println("=====>名称：" + path.getFileName());
                    String pt = path.getFileName().toString().substring(0, 3);
                    String ph = source + "\\" + pt + "\\" + pt + ".png";
                    System.out.println("=====>目标路径： " + ph);
//                    Files.delete(path);
                    Files.copy(path, Paths.get(ph));
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        });


//        try {
////            FileChannel from = new FileInputStream("src/data.txt").getChannel();
////            FileChannel to = new FileOutputStream("src/out.txt").getChannel();
////            from.transferTo(0,from.size(),to);
//
//        } catch (Exception e) {
//        }
    }
}
